package myapps.ttclient.adapter;

import java.util.ArrayList;

import myapps.ttclient.struct.PresentationWindowPropertiesStruct;

import myapps.ttclient.R;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class PPTSelectActiveWindowArrayAdapter extends ArrayAdapter<PresentationWindowPropertiesStruct> {
	private final Context context;
	private final ArrayList<PresentationWindowPropertiesStruct> arrayList;

	static class ViewHolder {
		public TextView tvPresentationName;
		public ImageView ivIsActive;
		
	}

	public PPTSelectActiveWindowArrayAdapter(Context context, int textViewResourceID, 
			ArrayList<PresentationWindowPropertiesStruct> arrayList) {
		super(context, textViewResourceID, arrayList);

		this.context = context;
		this.arrayList = arrayList;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View rowView = convertView;

		if (rowView == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			rowView = inflater.inflate(R.layout.select_active_window_rowlayout, null);

			ViewHolder viewHolder = new ViewHolder();
			viewHolder.tvPresentationName = (TextView) rowView.findViewById(R.id.tvPresentationName);
			viewHolder.ivIsActive = (ImageView) rowView.findViewById(R.id.ivIsActive);
			
			rowView.setTag(viewHolder);
		}

		ViewHolder holder = (ViewHolder) rowView.getTag();

		String name = arrayList.get(position).presentationName;
		Boolean isActive =  arrayList.get(position).isActive;
		
		holder.tvPresentationName.setText(name);
		
		if(isActive) {
			holder.ivIsActive.setImageResource(R.drawable.btn_radio_on);
		
		} else {
			holder.ivIsActive.setImageResource(R.drawable.btn_radio_off);
		
		}
		
		return rowView;
	}
}
